//    Copyright (C) Kherty.  All rights reserved.
namespace OpenLS.Chart.UI.Internals
{
    public class Scaler
    {
        public Scaler(AxisOrientation orientation, double? logBase, double minimum, double maximum)
        {
            _orientation = orientation;
            _logBase = logBase;
            _minimum = minimum;
            _maximum = maximum;
        }

        readonly AxisOrientation _orientation;
        double? _logBase;
        readonly double _minimum;
        readonly double _maximum;

        public double GetValue(double value, double screenMinimum, double screenMaximum)
        {
            if (_orientation == AxisOrientation.MaximumToMinimum)
                return GetValueImp(value, screenMaximum, screenMinimum);
            return GetValueImp(value, screenMinimum, screenMaximum);
        }

        private double GetValueImp(double value, double screenMinimum, double screenMaximum)
        {
            double len = screenMaximum - screenMinimum;
            double range = _maximum - _minimum;
            if (range == 0)
                return screenMinimum;
            return screenMinimum + (value - _minimum) / range * len;
        }
    }
}